#while 
#for 
#range()函数  可以有三个参数 ，分别控制 开始 结束+1 ，步长
# enumerate()函数  
#zip() 函数
# break return continue
#列表推导式 
list1 = [1,2,3]
list2 = [num*2 for num in list1]
print(list2)

a = enumerate(list1)
print(type(a))
print(type(range(100)))


str1 = '''
熊宁
杰益

王伟伟

青芳

玉琴
焦候涛
莫福
杨高旺
唐欢欢
韩旭
'''

str2 = '''
焦候涛 
熊宁 
玉琴 

骆龙 

韩旭 
杨高旺

杰益  

莫福  

伟伟

付青芳

李福  
'''
#找出str1独有的人名
def findSomeUnique(para1,para2):
    #找出para1与para2不共有的人名
    para1 = para1.splitlines()
    para1 = [nameStr.strip() for nameStr in para1]
    #这里有个瑕疵，没有去除掉列表中的空

    para2 = para2.splitlines()
    para2 = [nameStr.strip() for nameStr in para2]

    uniqueName = []
    for name in para1:
        if name in para2:
            continue
        else:
            uniqueName.append(name)
    
    return uniqueName


a = findSomeUnique(str1,str2)
print(a)

b = findSomeUnique(str2,str1)
print(b)


ageTable = '''
    诸葛亮, 28
    刘备, 48
    刘琦, 25
    赵云, 32
    张飞, 43
    关羽, 45
'''
def getNameAndAge(para1):
    para1 = para1.splitlines()

    list1=[]
    list2=[]
    for info in para1:
        info = info.strip()
        if info :
            name,age = info.split(',')
            if int(age.strip()) >= 30:
                list1.append(name)
            else:
                list2.append(name)
    print(f'年龄大于等于30岁的人有{list1}')
    print(f'年龄下于30岁的人有{list2}')

getNameAndAge(ageTable)

def calculate_score(para1):
    total = len(para1)
    win_score = 0
    draw_score = 0
    for match in para1:
        if match[0] == match[1]:
            draw_score += 1
            continue
        if '剪刀' in match and '石头' in match:
            if match.index('石头') == 0:
                win_score += 1
            else:
                continue
        elif '布' in match and '剪刀' in match:
            if match.index('剪刀') == 0:
                win_score += 1
            else:
                continue
        elif '布' in match and '石头' in match:
            if match.index('布') == 0:
                win_score += 1
            else:
                continue   
    lose_score = total - win_score - draw_score
    print(f'关羽赢了{win_score}局，平了{draw_score}局,张飞赢了{lose_score}局')

calculate_score([["剪刀", "石头"], ["布", "剪刀"], ["剪刀", "剪刀"]]) 
# 输出应该是： 张飞 3局赢了2局，平手一局，张飞胜出

calculate_score([["布", "石头"], ["石头", "剪刀"], ["石头", "剪刀"]]) 
# 输出应该是： 关羽 3局赢了3局，关羽胜出

list3 = [112,342,4234]
list4 = ('cai','pei','yan')
zip_a = zip(list3,list4)#返回的是一个zip类
print(type(zip_a))
for a in zip_a:
    print(a)

#冒泡排序  交换
maopao_list2 = [3,4,2,5,9,128,943,4,24,5]
def mao_pao(list1):
    list_length = len(list1)
    for i in range(list_length):
        #每次都从第一个开始把最大的冒泡上去
        j = 0
        #list_length-1-i是控制比较次数的，也可以按照下面的写法，只不过多了没有必要的几次循环，
        while j < list_length-1 :
            #> < 就是按照递增或者递减的方法来
            if list1[j] < list1[j+1]:
                c = list1[j]
                list1[j] = list1[j+1]
                list1[j+1] = c

            j += 1

# print(maopao_list2)
# mao_pao(maopao_list2)
# print(maopao_list2)

def mao_pao2(list1):
    list_length = len(list1)
    for i in range(list_length):
        #每次都从第一个开始把最大的冒泡上去
        
        for j in range(list_length-1):
            if list1[j] > list1[j+1]:
                # c = list1[j]
                # list1[j] = list1[j+1]
                # list1[j+1] = c
                list1[j],list1[j+1] = list1[j+1],list1[j]

print(maopao_list2)
mao_pao2(maopao_list2)
print(maopao_list2)
#列出质数

def list_zhishu(para1):
    zhishu_list = []
    for i in range(1,para1,1):
        for j in range(1,i+1,1):
            if i%j == 0 and j != 1 and j!=i:
                break
            if i == j :
                zhishu_list.append(i)
    
    return zhishu_list
a = list_zhishu(1000)
print(a)
    
def chuli_str(para1):
    result = ''
    content = para1.splitlines()
    for i in content:
        if i :
            name,salary = i.split(';')
            name = name.split(':')[1].strip()
            salary = salary.split(':')[1].strip()
            tax = int(salary)*0.1
            income = int(salary)*0.9
            result += f'\nname: {name:<10};  salary:  {salary:>10} ; tax: {tax:>10} ; income: {income:>10}'
    return result

str3 = '''
name: Jack   ;    salary:  12000
 name :Mike ; salary:  12300
name: Luk ;   salary:  10030
  name :Tim ;  salary:   9000
name: John ;    salary:  12000
name: Lisa ;    salary:   11000
'''
print(chuli_str(str3))

maopao_list3 = [3,4,2,5,9,128,943,4,24,5]
def maopao(para):
    changdu = len(para)
    for i in range(changdu):
        
        for j in range(changdu-i-1):
            
            if para[j] > para[j+1]:
                para[j+1],para[j] = para[j],para[j+1]
            

maopao(maopao_list3)
print(maopao_list3)